package com.lxw.weather.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import androidx.fragment.app.Fragment;

import com.lxw.weather.R;

import com.lxw.weather.model.DailyForecast;

import java.util.List;

public class DailyForecastFragment extends Fragment {
    private TextView rawDataText;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_daily_forecast, container, false);
        rawDataText = view.findViewById(R.id.rawDataText);
        return view;
    }

    public void updateData(List<DailyForecast> forecasts) {
        if (getActivity() != null && rawDataText != null) {
            StringBuilder sb = new StringBuilder();
            for (DailyForecast forecast : forecasts) {
                sb.append("日期: ").append(forecast.getDate()).append("\n")
                  .append("白天温度: ").append(forecast.getDayTemp()).append("\n")
                  .append("夜间温度: ").append(forecast.getNightTemp()).append("\n")
                  .append("天气: ").append(forecast.getDayWeather()).append("\n\n");
            }

            getActivity().runOnUiThread(() -> {
                rawDataText.setText(sb.toString());
                Log.d("RawDataDebug", "显示原始数据: " + sb.toString());
            });
        }
    }
}